Public Class DataReader
    Implements IDataReader

    Private _table As DataTable
    Private _connection As Connection

    Private _rowIdx As Integer

    Public Sub Close() Implements System.Data.IDataReader.Close
        _connection.Close()
    End Sub

    Public ReadOnly Property Depth() As Integer Implements System.Data.IDataReader.Depth
        Get
            Return 0
        End Get
    End Property

    Public Function GetSchemaTable() As System.Data.DataTable Implements System.Data.IDataReader.GetSchemaTable
        Dim schema As New DataTable()
        For Each column As DataColumn In _table.Columns
            schema.Columns.Add(column)
        Next
        Return schema
    End Function

    Public ReadOnly Property IsClosed() As Boolean Implements System.Data.IDataReader.IsClosed
        Get
            Return _connection.State = ConnectionState.Closed
        End Get
    End Property

    Public Sub New(ByVal table As DataTable, ByVal Connection As Connection)
        _rowIdx = -1
        _table = table
        _connection = Connection
    End Sub
    Public Function NextResult() As Boolean Implements System.Data.IDataReader.NextResult
        If _rowIdx + 1 >= _table.Rows.Count Then
            Return False
        Else
            Return True
        End If
    End Function

    Public Function Read() As Boolean Implements System.Data.IDataReader.Read
        _rowIdx += 1
        If _rowIdx >= _table.Rows.Count Then
            Return False
        Else
            Return True
        End If
    End Function

    Public ReadOnly Property RecordsAffected() As Integer Implements System.Data.IDataReader.RecordsAffected
        Get
            Return _table.Rows.Count
        End Get
    End Property

    Public ReadOnly Property FieldCount() As Integer Implements System.Data.IDataRecord.FieldCount
        Get
            Return _table.Columns.Count
        End Get
    End Property

    Public Function GetBoolean(ByVal i As Integer) As Boolean Implements System.Data.IDataRecord.GetBoolean
        Return _table.Rows(_rowIdx)(i)
    End Function

    Public Function GetByte(ByVal i As Integer) As Byte Implements System.Data.IDataRecord.GetByte
        Return _table.Rows(_rowIdx)(i)
    End Function

    Public Function GetBytes(ByVal i As Integer, ByVal fieldOffset As Long, ByVal buffer() As Byte, ByVal bufferoffset As Integer, ByVal length As Integer) As Long Implements System.Data.IDataRecord.GetBytes

    End Function

    Public Function GetChar(ByVal i As Integer) As Char Implements System.Data.IDataRecord.GetChar
        Return _table.Rows(_rowIdx)(i)
    End Function

    Public Function GetChars(ByVal i As Integer, ByVal fieldoffset As Long, ByVal buffer() As Char, ByVal bufferoffset As Integer, ByVal length As Integer) As Long Implements System.Data.IDataRecord.GetChars

    End Function

    Public Function GetData(ByVal i As Integer) As System.Data.IDataReader Implements System.Data.IDataRecord.GetData
        Return _table.Rows(_rowIdx)(i)
    End Function

    Public Function GetDataTypeName(ByVal i As Integer) As String Implements System.Data.IDataRecord.GetDataTypeName
        Return _table.Rows(_rowIdx)(i).GetType().ToString
    End Function

    Public Function GetDateTime(ByVal i As Integer) As Date Implements System.Data.IDataRecord.GetDateTime
        Return _table.Rows(_rowIdx)(i)
    End Function

    Public Function GetDecimal(ByVal i As Integer) As Decimal Implements System.Data.IDataRecord.GetDecimal
        Return _table.Rows(_rowIdx)(i)
    End Function

    Public Function GetDouble(ByVal i As Integer) As Double Implements System.Data.IDataRecord.GetDouble
        Return _table.Rows(_rowIdx)(i)
    End Function

    Public Function GetFieldType(ByVal i As Integer) As System.Type Implements System.Data.IDataRecord.GetFieldType
        Return _table.Rows(_rowIdx)(i).GetType
    End Function

    Public Function GetFloat(ByVal i As Integer) As Single Implements System.Data.IDataRecord.GetFloat
        Return _table.Rows(_rowIdx)(i)
    End Function

    Public Function GetGuid(ByVal i As Integer) As System.Guid Implements System.Data.IDataRecord.GetGuid
        Return _table.Rows(_rowIdx)(i)
    End Function

    Public Function GetInt16(ByVal i As Integer) As Short Implements System.Data.IDataRecord.GetInt16
        Return _table.Rows(_rowIdx)(i)
    End Function

    Public Function GetInt32(ByVal i As Integer) As Integer Implements System.Data.IDataRecord.GetInt32
        Return _table.Rows(_rowIdx)(i)
    End Function

    Public Function GetInt64(ByVal i As Integer) As Long Implements System.Data.IDataRecord.GetInt64
        Return _table.Rows(_rowIdx)(i)
    End Function

    Public Function GetName(ByVal i As Integer) As String Implements System.Data.IDataRecord.GetName
        Return _table.Columns(i).ColumnName
    End Function

    Public Function GetOrdinal(ByVal name As String) As Integer Implements System.Data.IDataRecord.GetOrdinal
        Return _table.Columns.IndexOf(name)
    End Function

    Public Function GetString(ByVal i As Integer) As String Implements System.Data.IDataRecord.GetString
        Return _table.Rows(_rowIdx)(i)
    End Function

    Public Function GetValue(ByVal i As Integer) As Object Implements System.Data.IDataRecord.GetValue
        Return _table.Rows(_rowIdx)(i)
    End Function

    Public Function GetValues(ByVal values() As Object) As Integer Implements System.Data.IDataRecord.GetValues

    End Function

    Public Function IsDBNull(ByVal i As Integer) As Boolean Implements System.Data.IDataRecord.IsDBNull
        Return _table.Rows(_rowIdx)(i) Is Nothing
    End Function

    Default Public Overloads ReadOnly Property Item(ByVal i As Integer) As Object Implements System.Data.IDataRecord.Item
        Get
            Return _table.Rows(_rowIdx)(i)
        End Get
    End Property

    Default Public Overloads ReadOnly Property Item(ByVal name As String) As Object Implements System.Data.IDataRecord.Item
        Get
            Return _table.Rows(_rowIdx)(name)
        End Get
    End Property

    Private disposedValue As Boolean = False        ' To detect redundant calls

    ' IDisposable
    Protected Overridable Sub Dispose(ByVal disposing As Boolean)
        If Not Me.disposedValue Then
            If disposing Then
                ' TODO: free managed resources when explicitly called
            End If

            ' TODO: free shared unmanaged resources
        End If
        Me.disposedValue = True
    End Sub

#Region " IDisposable Support "
    ' This code added by Visual Basic to correctly implement the disposable pattern.
    Public Sub Dispose() Implements IDisposable.Dispose
        ' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.
        Dispose(True)
        GC.SuppressFinalize(Me)
    End Sub
#End Region

End Class
